import {
    gotoLoginPage,
    gotoServiceCardPage
} from "./pageRoute.js";
import {
    readUserInfo
} from "./user-service.js"

function loginCheck() {
    return new Promise((resolve, reject) => {
        if (readUserInfo()) {
            resolve();
        } else {
            gotoLoginPage();
            reject();
        }
    })
}

function premissionCheck(premission) {
    return new Promise((resolve, reject) => {
        if (premission) {
            resolve();
        } else {
            gotoServiceCardPage();
            reject()
        }
    })
}

function checkAll(premission) {
    return new Promise((resolve, reject) => {
        loginCheck().then(() => {
            return premissionCheck(premission)
        }).then(() => {
            resolve();
        }).catch(() => {
            reject();
        })
    })
}

module.exports = {
    loginCheck,
    premissionCheck,
    checkAll
}